// ES5之前使用var关键字定义的变量只有函数内部有作用域
var arr = [1, 2, 3]

for (var i = 0; i < arr.length; ++i) {
  setTimeout(function () {
    console.log(i)
  }, 1000)
}

for (var k = 0; k < arr.length; ++k) {
  function foo(k) {
    console.log(k)
  }
  setTimeout(foo.bind(null, k), 2000)
}
function bar(i) {
  return function () {
    console.log(i)
  }
}
for (var j = 0; j < arr.length; ++j) {
  setTimeout(bar(j), 3000)
}
